# this script is used to calculate the application of the best pattern
# to the symbols in the groups (in-sample and out-of-sample)


##################################################################
######## INDEX_MAJORS ############################################
######## in sample ###############################################
######## optimized for best mean #################################
group <- "INDEX_MAJORS"
symbol <- ""
pattern <- c("DownsideTasukiGap_D","DragonflyDoji_D","UpsideTasukiGap_U","MorningStar_D")
direction <- c("short"            ,"long"           ,"long"             ,"long")
pattern <- c(pattern,    "PiercingPattern_D","ThreeBlackCrows_U","GravestoneDoji_U","BlackMarubozu_U")
direction <- c(direction,"short"            ,"long"             ,"long"            ,"long"           )
TxnFees <- -20
LL <- c( 1, 4, 3,10,   9, 0, 0, 0)
WL <- c(10,20, 0, 0,   4, 2, 2,14)
applyStrategy(group, symbol, pattern, direction, LL, WL, initEq=50000, TxnFees=TxnFees)
PerformanceSummary(group, latex=TRUE, method="mean")

######## out of sample ###########################################
######## optimized for best mean #################################
group <- "INDEX_MAJORS_OOS"
symbol <- ""
applyStrategy(group, symbol, pattern, direction, LL, WL, initEq=50000, TxnFees=TxnFees)
PerformanceSummary(group, latex=TRUE, method="mean")

######## in sample ###############################################
######## optimized for best ratio #################################
group <- "INDEX_MAJORS"
symbol <- ""
pattern <- c("ThreeBlackCrows_U","DownsideTasukiGap_D","DragonflyDoji_D","UpsideTasukiGap_U")
direction <- c("long"           ,"short"              ,"long"           ,"long")
pattern <- c(pattern,    "GravestoneDoji_U","PiercingPattern_D","MorningStar_D")
direction <- c(direction,"long"            ,"short"            ,"long"         )
TxnFees <- -20
LL <- c( 0, 1, 1, 3,   2, 0, 3)
WL <- c( 2,10,20, 0,   2, 2, 0)
applyStrategy(group, symbol, pattern, direction, LL, WL, initEq=50000, TxnFees=TxnFees)
PerformanceSummary(group, latex=TRUE, method="ratio")

######## out of sample ###########################################
######## optimized for best mean #################################
group <- "INDEX_MAJORS_OOS"
symbol <- ""
applyStrategy(group, symbol, pattern, direction, LL, WL, initEq=50000, TxnFees=TxnFees)
PerformanceSummary(group, latex=TRUE, method="ratio")




##################################################################
######## DJI_STOCKS ##############################################
######## in sample ###############################################
######## optimized for best mean #################################
group <- "DJI_STOCKS"
symbol <- ""
pattern <- c("BlackMarubozu_D", "UpsideTasukiGap_U", 
             "GravestoneDoji_U", "InvertedHammer_D", 
             "ThreeWhiteSoldiers_D", "ThreeBlackCrows_U")
direction <- c("long", "short", "long", "long", "long", "long")
TxnFees <- -20
LL <- c(0 ,0 ,4 ,0 ,0 ,10)
WL <- c(20,14,12,10,16,20)
applyStrategy(group, symbol, pattern, direction, LL, WL, initEq=50000, TxnFees=TxnFees)
PerformanceSummary(group, latex=TRUE, method="mean")

######## out of sample ###########################################
######## optimized for best mean #################################
group <- "DJI_STOCKS_OOS"
symbol <- ""
applyStrategy(group, symbol, pattern, direction, LL, WL, initEq=50000, TxnFees=TxnFees)
PerformanceSummary(group, latex=TRUE, method="mean")

######## in sample ###############################################
######## optimized for best ratio ################################
group <- "DJI_STOCKS"
symbol <- ""
LL <- c(0 ,1 ,4 ,0 ,7 ,3)
WL <- c(20,14,12,10,4 ,0)
applyStrategy(group, symbol, pattern, direction, LL, WL, initEq=50000, TxnFees=TxnFees)
PerformanceSummary(group, latex=TRUE, method="ratio")

######## out of sample ###########################################
######## optimized for best ratio #################################
group <- "DJI_STOCKS_OOS"
symbol <- ""
applyStrategy(group, symbol, pattern, direction, LL, WL, initEq=50000, TxnFees=TxnFees)
PerformanceSummary(group, latex=TRUE, method="ratio")

##################################################################
######## SMALL CAPS ##############################################
######## in sample ###############################################
######## optimized for best mean #################################
group <- "SMALL_CAPS"
symbol <- ""
pattern <- c("BlackMarubozu_D","WhiteMarubozu_D","DragonflyDoji_D","BlackMarubozu_U","InvertedHammer_D")
direction <- c("long"         ,"short"          ,"short"          ,"long"           ,"long")
pattern <- c(pattern,    "ShootingStar_U","WhiteMarubozu_U","GravestoneDoji_U","BullDoji_D","ThreeBlackCrows_U")
direction <- c(direction,"long"          ,"short"          ,"long"            ,"long"      ,"long")
LL <- c(0 ,0 ,0 ,0 ,0 ,   0, 0, 0, 0, 0)
WL <- c(14,6 ,4 ,10,8 ,  10, 4, 4,10, 2)
TxnFees <- -20
applyStrategy(group, symbol, pattern, direction, LL, WL, initEq=50000, TxnFees=TxnFees)
PerformanceSummary(group, latex=TRUE, method="mean")

######## out of sample ###########################################
######## optimized for best mean #################################
group <- "SMALL_CAPS_OOS"
symbol <- ""
applyStrategy(group, symbol, pattern, direction, LL, WL, initEq=50000, TxnFees=TxnFees)
PerformanceSummary(group, latex=TRUE, method="mean")

######## optimized for best ratio ################################
group <- "SMALL_CAPS"
symbol <- ""
pattern <- c("BlackMarubozu_D","GravestoneDoji_U","WhiteMarubozu_D","BlackMarubozu_U","ThreeBlackCrows_U")
direction <- c("long"         ,"long"            ,"short"          ,"long"           ,"long")
pattern <- c(pattern,    "DragonflyDoji_D","HangingMan_U","InvertedHammer_D","ShootingStar_U","WhiteMarubozu_U")
direction <- c(direction,"short"          ,"short"       ,"long"            ,"long"          ,"short")
LL <- c(1 ,1 ,1 ,1 ,0 ,   1, 2, 2, 0, 0)
WL <- c(4 ,4 ,4 ,8 ,2 ,   2, 4, 4,10, 2)
TxnFees <- -20
applyStrategy(group, symbol, pattern, direction, LL, WL, initEq=50000, TxnFees=TxnFees)
PerformanceSummary(group, latex=TRUE, method="ratio")

######## out of sample ###########################################
######## optimized for best ratio ################################
group <- "SMALL_CAPS_OOS"
symbol <- ""
applyStrategy(group, symbol, pattern, direction, LL, WL, initEq=50000, TxnFees=TxnFees)
PerformanceSummary(group, latex=TRUE, method="ratio")



##################################################################
######## METALS ##################################################
######## in sample ###############################################
######## optimized for best mean #################################
group <- "METALS"
symbol <- ""
pattern <- c("BlackMarubozu_D","WhiteMarubozu_D","GravestoneDoji_U","Hammer_D","HangingMan_U")
direction <- c("long"         ,"long"           ,"long"            ,"long"    ,"long")
pattern <- c(pattern,    "EveningStar_U","BullHarami_D","ThreeWhiteSoldiers_D","GapDown_D")
direction <- c(direction,"short"        ,"long"        ,"short"               ,"short")
LL <- c(6 ,5 ,4 ,0 ,12 ,   3, 5, 3, 0)
WL <- c(10,10,10,16,10 ,  12, 6, 4, 4)
TxnFees <- -20
applyStrategy(group, symbol, pattern, direction, LL, WL, initEq=50000, TxnFees=TxnFees)
PerformanceSummary(group, latex=TRUE, method="mean")

######## out of sample ###########################################
######## optimized for best mean #################################
group <- "METALS_OOS"
symbol <- ""
applyStrategy(group, symbol, pattern, direction, LL, WL, initEq=50000, TxnFees=TxnFees)
PerformanceSummary(group, latex=TRUE, method="mean")

##################################################################
######## optimized for best ratio ################################
group <- "METALS"
symbol <- ""
pattern <- c("Hammer_D","BlackMarubozu_D","WhiteMarubozu_D","GravestoneDoji_U","HangingMan_U")
direction <- c("long"  ,"long"           ,"long"           ,"long"            ,"long")
pattern <- c(pattern,    "BullHarami_D","EveningStar_U","ThreeWhiteSoldiers_D","BullDoji_D")
direction <- c(direction,"long"        ,"short"        ,"short"               ,"long")
LL <- c(1 ,6 ,5 ,4 ,2  ,   2, 3, 2, 7)
WL <- c(16,10,10,10,10 ,   6,12, 4, 2)
TxnFees <- -20
applyStrategy(group, symbol, pattern, direction, LL, WL, initEq=50000, TxnFees=TxnFees)
PerformanceSummary(group, latex=TRUE, method="ratio")

######## out of sample ###########################################
######## optimized for best ratio ################################
group <- "METALS_OOS"
symbol <- ""
applyStrategy(group, symbol, pattern, direction, LL, WL, initEq=50000, TxnFees=TxnFees)
PerformanceSummary(group, latex=TRUE, method="ratio")

##################################################################
######## AGRICULTURE #############################################
######## in sample ###############################################
######## optimized for best mean #################################
group <- "AGRICULTURE"
symbol <- ""
pattern <- c("GapDown_D","AboveTheStomache_D","ThreeBlackCrows_U","GapUp_D")
direction <- c("long"   ,"long"              ,"long"             ,"long")
pattern <- c(pattern, "Hammer_D","BullHarami_D","GapDown_U","BullDoji_D","BlackMarubozu_D")
direction <- c(direction, "long"    ,"short"       ,"short"    ,"long"      ,"long")
LL <- c(0 ,6 ,1 ,3   ,   7, 0, 2, 3, 1)
WL <- c(0 ,0 ,0 ,20  ,   6,12,14, 4,14)
TxnFees <- -20
applyStrategy(group, symbol, pattern, direction, LL, WL, initEq=50000, TxnFees=TxnFees)
PerformanceSummary(group, latex=TRUE, method="mean")

######## out of sample ###########################################
######## optimized for best mean #################################
group <- "AGRICULTURE_OOS"
symbol <- ""
applyStrategy(group, symbol, pattern, direction, LL, WL, initEq=50000, TxnFees=TxnFees)
PerformanceSummary(group, latex=TRUE, method="mean")

##################################################################
######## optimized for best ratio ################################
group <- "AGRICULTURE"
symbol <- ""
pattern <- c("ThreeBlackCrows_U","BlackMarubozu_D","HangingMan_U","ThreeWhiteSoldiers_D","GapDown_U")
direction <-c("long"            ,"long"           ,"long"        ,"short"               ,"short")
pattern <-c(pattern,"BullEngulfing_D","AboveTheStomache_D","BullHarami_D","BullDoji_D")
direction <-c(direction, "long"      ,"long"              ,"short"       ,"short")
LL <- c(1 ,1 ,1 ,1 ,1  ,   1, 6, 0, 2)
WL <- c(0 ,14,8 ,10,14 ,   0, 0,12, 4)
TxnFees <- -20
applyStrategy(group, symbol, pattern, direction, LL, WL, initEq=50000, TxnFees=TxnFees)
PerformanceSummary(group, latex=TRUE, method="ratio")

######## out of sample ###########################################
######## optimized for best ratio #################################
group <- "AGRICULTURE_OOS"
symbol <- ""
applyStrategy(group, symbol, pattern, direction, LL, WL, initEq=50000, TxnFees=TxnFees)
PerformanceSummary(group, latex=TRUE, method="ratio")